<template>
  <div class="before-login-view">
    <div class="bg-img">
      <div class="top-delete-icon" @click="goBack"><van-icon name="cross" /></div>
    </div>
    <div class="form">
      <form>
        <div class="phone-ipt-wrap">
          <span class="add86">+86</span
          ><input type="text" placeholder="输入手机号" v-model="phoneNumber" />
        </div>
        <div class="captcha-ipt-wrap">
          <input type="text" placeholder="输入验证码" ref="theCaptcha" />
          <div class="getCaptcha" ref="Captcha" @click="getCaptcha">
            获取验证码
          </div>
        </div>
      </form>
    </div>
    <div class="to-agree">
      <div class="checkbox-wrap">
        <input type="checkbox" ref="agreeCheck" />
      </div>
      <div class="agree-text">
        我已阅读并同意 <span class="blue-text">《用户服务协议》</span> 和<span
          class="blue-text"
          >《隐私政策》</span
        >
      </div>
    </div>
    <div class="login-btn" @click="login">注册/登录</div>
    <div class="password-to-login">账号密码登录 <van-icon name="arrow" /></div>
    <div class="third-to-login">
      <div class="line"></div>
      <div class="text">第三方账号登录</div>
      <div class="line"></div>
    </div>
    <div class="bottom-icon">
      <div class="icon" v-for="(item, index) in iconData" :key="index">
        <img class="auto-img" :src="item.icon" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "beforeLogin",
  data() {
    return {
      iconData: [
        {
          icon: require("@/assets/images/user/IV1.png"),
        },
        {
          icon: require("@/assets/images/user/GLP.png"),
        },
        {
          icon: require("@/assets/images/user/Oph.png"),
        },
      ],
      timer: null,
      seconds: 60,
      phoneNumber: "",
      captcha: "",
    };
  },
  methods: {
    getCaptcha() {
      if (!this.$refs.agreeCheck.checked) {
        this.$toast("请先勾选协议");
      } else {
        this.captcha = 123456;
        this.$toast(`验证码为:${this.captcha}`);
        this.$refs.Captcha.textContent = this.seconds;
        this.timer = setInterval(() => {
          this.$refs.Captcha.textContent = this.seconds;
          this.seconds--;
          this.$refs.Captcha.style.pointerEvents = "none";
          if (this.seconds == 0) {
            clearInterval(this.timer);
            this.timer = null;
            this.$refs.Captcha.textContent = "获取验证码";
            this.$refs.Captcha.style.pointerEvents = "auto";
            this.seconds = 60;
          }
        }, 1000);
      }
    },
    login() {
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (this.captcha == "" || this.captcha != this.$refs.theCaptcha.value) {
        this.$toast("请输入正确的验证码");
      } else if (!reg.test(this.phoneNumber)) {
        this.$toast("请输入正确的手机号格式");
      } else{
        this.$toast('登录成功')
        window.localStorage.setItem('appActiveIndex',4)
        window.localStorage.setItem('token','u235gty6h88')
        this.phoneNumber=''
        this.captcha=''
        this.$router.push({name:'user'})
      }
    },
    goBack() {
      this.$router.go(-1)
    },
  },
};
</script>

<style lang="scss" scoped>
.before-login-view {
  width: 100vw;
  height: 100vh;
  padding: 10px;
  box-sizing: border-box;
  background-color: #fff;
  z-index: 999;
  letter-spacing: 0;
  .bg-img {
    width: 100vw;
    position: relative;
    left: -10px;
    top: -10px;
    height: 200px;
    background-image: url("@/assets/images/user/Snipaste_2022-11-19_15-52-39.png");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
  }
  .top-delete-icon {
    position: absolute;
    top: 20px;
    left: 10px;
    font-size: 20px;
  }
  .form {
    margin-top: 50px;
    input {
      width: calc(100% - 50px);
      height: 25px;
    }
    input::-webkit-input-placeholder {
      /* 使用webkit内核的浏览器 */
      color: #aaa;
      font-size: 16px;
      font-weight: 600;
    }
    input:-moz-placeholder {
      /* Firefox版本4-18 */
      color: #aaa;
      font-size: 16px;
      font-weight: 600;
    }
    input::-moz-placeholder {
      /* Firefox版本19+ */
      color: #aaa;
      font-size: 16px;
      font-weight: 600;
    }
    input:-ms-input-placeholder {
      /* IE浏览器 */
      color: #aaa;
      font-size: 16px;
      font-weight: 600;
    }
    .phone-ipt-wrap {
      border-bottom: 1px solid #ddd;
      padding-bottom: 6px;
      .add86 {
        font-weight: 600;
        font-size: 16px;
        margin-right: 10px;
      }
    }
    .captcha-ipt-wrap {
      border-bottom: 1px solid #ddd;
      padding-bottom: 6px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 10px;
      .getCaptcha {
        width: 80px;
        height: 22px;
        line-height: 22px;
        text-align: center;
        background-color: #eee;
        border-radius: 4px;
        color: #666;
        position: relative;
        top: -2px;
      }
    }
  }
  .to-agree {
    display: flex;
    align-items: center;
    width: 320px;
    margin: 30px auto 0;
    .checkbox-wrap {
      input {
        width: 18px;
        height: 18px;
        border: 1px solid rgb(108, 99, 99);
        margin-right: 10px;
      }
    }
    .agree-text {
      color: #999;
      .blue-text {
        color: rgb(23, 153, 218);
      }
    }
  }
  .login-btn {
    width: 100%;
    height: 50px;
    text-align: center;
    line-height: 50px;
    background-color: rgb(245, 245, 245);
    color: #999;
    font-size: 16px;
    margin-top: 10px;
  }
  .password-to-login {
    width: 100%;
    text-align: center;
    margin-top: 30px;
    font-weight: 600;
    font-size: 14px;
    .van-icon-arrow {
      color: #aaa;
    }
  }
  .third-to-login {
    display: flex;
    align-items: center;
    color: #666;
    width: 250px;
    margin: 30px auto 15px;
    position: relative;
    left: 15px;
    .text {
      margin: 0 20px;
    }
    .line {
      width: 45px;
      height: 2px;
      background-color: #ccc;
    }
  }
  .bottom-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    .icon {
      width: 40px;
      height: 40px;
      border-radius: 999px;
      margin: 0 30px;
    }
  }
}
</style>